<?php


namespace app\admin\business;


use app\admin\controller\Common;
use think\facade\Db;

class CashBus extends Common
{
    public function __construct()
    {
        parent::__construct();
    }


    /**
     * 获取提现列表
     * @param $where
     * @param $sort_by
     * @param $sort_order
     * @param $pageSize
     * @param $page
     * @return array
     * @throws \think\db\exception\DbException
     */
    public static function getList($where,$sort_by,$sort_order,$pageSize,$page){
        $list = Db::name('cash')->alias('a')
            ->join('user b','b.user_id = a.user_id','left')
            ->where($where)
            ->field('a.*,b.username,b.mobile')
            ->order($sort_by . ' ' . $sort_order)
            ->paginate(array('list_rows' => $pageSize, 'page' => $page))
            ->toArray();
        return $list;
    }

    /**
     * 获取订单列表
     * @param $where
     * @param $sort_by
     * @param $sort_order
     * @param $pageSize
     * @param $page
     * @return array
     * @throws \think\db\exception\DbException
     */
    public static function getReturnList($where,$sort_by,$sort_order,$pageSize,$page){
        $list = Db::name('return_orders')->alias('a')
            ->join('user b', 'a.user_id = b.user_id', 'left')
            ->where($where)
            ->order($sort_by . ' ' . $sort_order)
            ->field('a.*,b.shop_name')
            ->paginate(array('list_rows' => $pageSize, 'page' => $page))
            ->toArray();
        return $list;
    }



    /**
     * 获取文章评论
     * @param $article_id
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function getComment($article_id){
        $comment = Db::name('comment')->alias('a')
            ->join('user b','b.user_id = a.user_id','left')
            ->where('a.article_id',$article_id)
            ->where('a.is_reply',0)
            ->field('a.id,a.article_id,a.reply_id,a.user_id,a.like_count,a.content,b.username,b.photo,a.create_time')
            ->order('a.id','desc')
            ->select()->toArray();
//        foreach ($comment as $k => $v) {
//            if ($v['reply_id'] != 0) {
//                $reply = Db::name('comment')->alias('a')
//                    ->join('user b', 'b.user_id = a.user_id', 'left')
//                    ->where('id', 'in', $v['reply_id'])
//                    ->field('a.id,a.reply_id,a.user_id,a.like_count,a.content,b.username,b.photo,a.create_time')
//                    ->order('a.id', 'desc')
//                    ->select()->toArray();
//                $comment[$k]['reply'] = $reply;
//            }
//        }
        return $comment;
    }

}